﻿<%@ Page Title="" Language="C#" MasterPageFile="~/Views/Shared/Site.master"   Inherits="System.Web.Mvc.ViewPage" %>
<%@ Register src="BookStatus.ascx" tagname="BookStatus" tagprefix="uc1" %>
<%@ Register assembly="System.Web.DataVisualization, Version=3.5.0.0, Culture=neutral, PublicKeyToken=31bf3856ad364e35" namespace="System.Web.UI.DataVisualization.Charting" tagprefix="asp" %>


<asp:Content ID="Content1" ContentPlaceHolderID="MainContentPlaceHolder" runat="server">

    <form id="form1" runat="server">
Days Together:<asp:Literal runat="server"></asp:Literal><br />
<div id="leftNav">
    <ul>
        <li><%= Html.ActionLink("Add Book", "BookNew") %></li>
        <li><%= Html.ActionLink("All", "All") %></li>
        <li><%= Html.ActionLink("Current Reading", "Current") %></li>
        <li><%= Html.ActionLink("Finished", "Finished") %></li>
        <li><%= Html.ActionLink("Not Finished", "NotFinished")%></li>
        <li><%= Html.ActionLink("UnOpened", "UnOpened") %></li>
    </ul>
    <ul>
    <%
        List<int> yl = (List<int>)ViewData["YearList"];
        if (yl != null) {
            foreach (int item in yl) {
                Response.Write("<li>" + Html.ActionLink(item.ToString(),"All",new { id=item}) + "</li>");
            }
        }
        
     %>
     </ul>
   
 </div>
  <div  style="width:350px;float:left;text-align:left;padding-left:10px;">
 <div class="SectionTitle" style="text-align:center;">Reading Stats
      </div>
      
 <uc1:BookStatus ID="BookStatus1" 
         runat="server" />
 </div>
    </form>
<%
    Frogism.Web.Models.IBookViewData model2 = (Frogism.Web.Models.IBookViewData)Model;
    
    %>
    
<script language="javascript" type="text/javascript">
    $(document).ready(function() {
        $(".DashboardTable").find('tr:even').addClass('AltColumn');
//        $(".AuthorName")
//            .mouseover(function() { showDetails(this) });

    });
    function showDetails(link) {
        var box = $(link).next();
        box.show();
        box.html('');
        $('<img />')
            .attr('src', '<%=Url.Content("~/images/loadingAnimation.gif") %>')
            .attr('alt', 'loading...').appendTo(box);

        var url = link.href;

        //     
    $.ajax({
        url: url,
        type: "Get",
        dataType: "json",
        success: function(results) { loadBookDetails(box, results); }
    });

}
//    function hideDetails(obj) {
//        $(obj).next().hide();
//    }
    function loadBookDetails(box, result) {

       // box.html('');
      //  $('<div />').attr("style", "font-size:.8em;float:left;position:relative;width:250px;height:250px;background-color:white").html(result.Title2).appendTo(box);

      //  overlib(result.Title2, CAPTION, 'Account ' + result.Title2 + ' Specifics', FGCOLOR, '#eeeeee', BGCOLOR, '#79C900', BORDER, 1, CAPTIONFONT, 'Garamond', TEXTSIZE, 1);
    }
</script>
	<table class="DashboardTable" style="float:left;" cellspacing="0" cellpadding="1">
				<tr>
				<!--	<th>Rating</th> -->
					<th>Title</th>
					<th>Author</th>
					<th>Pages</th>
					<th>Read</th>
					<th>To Go</th>
					<th>Year Read</th>
					<th>%</th>
				</tr>
				
<%
    foreach (var i in model2.Books)
    {
        %>
        <tr> 
			<td><img alt="status" width="16px" height="16px" src='<%= Url.Content("~/images/"+model2.StatusImage(i)) %>' /><%=Html.ActionLink(i.Title, "ReadsByBook", new { id = i.Id, title = i.Title })%>&nbsp;</td>				
			<td><%= Html.ActionLink(i.Author.Name, "Summary", new { id = i.Id }, new { @class = "AuthorName" })%>&nbsp;<div></div></td>	
			<td class="NumberCell"><%=i.TotalPages%>&nbsp;</td>	
			<td class="NumberCell"><%=i.TotalRead%>&nbsp;</td>	
			<td class="NumberCell"><%= Html.ActionLink(i.ToGo.ToString(), "UpdateToday", new { id = i.Id ,width=350,height=100}, new { alt = "Update Read for Today", @class = "thickbox" })%></td>
			<td class="NumberCell"><%=i.YearRead%>&nbsp;</td>		
			<td class="NumberCell"><%= String.Format("{0:N2}",i.PercentRead)%>&nbsp;</td>	
		</tr>
 <%   }				
		
%>
				   <tr>
				        <td>Totals</td>
				        <td></td>
				        <td class="NumberCell"><%= String.Format("{0:0,0}",model2.TotalPages) %></td>
				        <td class="NumberCell"><%= String.Format("{0:0,0}", model2.TotalRead)%></td>
				        <td class="NumberCell"><%= String.Format("{0:0,0}", model2.TotalToGo)%></td>
				        <td class="NumberCell"><%= String.Format("{0:0,0}", model2.TotalYearRead)%></td>
				        <td class="NumberCell"><%= String.Format("{0:N2}", model2.TotalPercent)%></td>
				    </tr>
	
				</table>
				<%
                                //IEnumerable<Frogism.Core.YearStat> status = (IEnumerable<Frogism.Core.YearStat>)this.ViewData["YearStats"];

                                //IEnumerable<Frogism.Core.YearStat> stats = (IEnumerable<Frogism.Core.YearStat>)this.ViewData["MonthStats"];

                                //foreach (var v in status)
                                //{
                                //    Chart1.Series["Series1"].Points.Add(new DataPoint(v.Year, Math.Round(v.PagesRead / 100d, 2)));
                                //    Chart1.Series["Series2"].Points.Add(new DataPoint(v.Year, v.BooksFinished));
                                //}

                                //foreach (var v in stats)
                                //{
                                //    Chart2.Series["Series1"].Points.Add(new DataPoint(v.Year, v.PagesRead));
                                //    Chart2.Series["Series2"].Points.Add(new DataPoint(v.Year, v.HistoricRead));
                                    
                                //}
                                //Chart2.Titles[0].Text = "Pages Read By Month for " + this.ViewData["MonthStatsYear"];
                                // Set fast line chart type
                                //Chart1.Series["Series1"].ChartType = SeriesChartType.Column;
                                //Chart1.Series["Series2"].ChartType = SeriesChartType.Column;
							
							 %>
	<%--			 <div style="float:left">
<asp:chart id="Chart1" runat="server" ImageLocation="~/TempImages/ChartPic_#SEQ(300,3)" imagetype="Png" BackColor="WhiteSmoke" BorderWidth="2" BackGradientStyle="TopBottom" BackSecondaryColor="White" Palette="BrightPastel" BorderDashStyle="Solid" BorderColor="26, 59, 105" Height="296px" Width="412px">
								<titles>
									<asp:title ShadowColor="32, 0, 0, 0" Font="Trebuchet MS, 12pt, style=Bold" ShadowOffset="3" Text="Pages Read By Year." ForeColor="26, 59, 105"></asp:title>
								</titles>
								<legends>
									<asp:legend Enabled="True" Docking="Bottom" LegendStyle="Column" IsTextAutoFit="True" Name="Default" BackColor="Transparent" Font="Trebuchet MS, 8.25pt, style=Bold"></asp:legend>
								</legends>
								<borderskin skinstyle="Emboss"></borderskin>
								<series>
									<asp:series LegendText="Hundreds of pages read" Name="Series1" ChartType="Column" Color="YellowGreen" ShadowColor="Black" BorderColor="180, 26, 59, 105" IsValueShownAsLabel="true" ></asp:series>
									<asp:series Name="Series2" LegendText="Books Finished" ChartType="Column" Color="Red" ShadowColor="Black" BorderColor="180, 26, 59, 105"  IsValueShownAsLabel="true"   ></asp:series>
								</series>
								<chartareas>
									<asp:chartarea Name="ChartArea1" BorderColor="64, 64, 64, 64" BorderDashStyle="Solid" BackSecondaryColor="White" BackColor="Gainsboro" ShadowColor="Transparent" BackGradientStyle="TopBottom">
										<area3dstyle Rotation="10" perspective="10" Inclination="15" IsRightAngleAxes="False" wallwidth="0" IsClustered="False"></area3dstyle>
										<axisy linecolor="64, 64, 64, 64" IsLabelAutoFit="False">
											<labelstyle font="Trebuchet MS, 8.25pt, style=Bold" />
											<majorgrid linecolor="64, 64, 64, 64" />
										</axisy>
										<axisx linecolor="64, 64, 64, 64" IsLabelAutoFit="False">
											<labelstyle font="Trebuchet MS, 8.25pt, style=Bold" />
											<majorgrid linecolor="64, 64, 64, 64" />
										</axisx>
									</asp:chartarea>
								</chartareas>
							</asp:chart>
						
			</div>--%>
			<%--<div style="float:left">
<asp:chart id="Chart2" runat="server" ImageLocation="~/TempImages/ChartPic_#SEQ(300,3)" imagetype="Png" BackColor="WhiteSmoke" BorderWidth="2" BackGradientStyle="TopBottom" BackSecondaryColor="White" Palette="BrightPastel" BorderDashStyle="Solid" BorderColor="26, 59, 105" Height="296px" Width="412px">
								<titles>
									<asp:title ShadowColor="32, 0, 0, 0" Font="Trebuchet MS, 12pt, style=Bold" ShadowOffset="3" Text="Pages Read By Month." ForeColor="26, 59, 105"></asp:title>
								</titles>
								<legends>
									<asp:legend Enabled="True" Docking="Bottom" LegendStyle="Column" IsTextAutoFit="True" Name="Default" BackColor="Transparent" Font="Trebuchet MS, 8.25pt, style=Bold"></asp:legend>
				    				
							
								</legends>
								<borderskin skinstyle="Emboss"></borderskin>
								<series>
									<asp:series LegendText="Pages Read" Name="Series1" ChartType="Column" Color="YellowGreen" ShadowColor="Black" BorderColor="180, 26, 59, 105" IsValueShownAsLabel="true" ></asp:series>
									<asp:series Name="Series2" LegendText="Previous Year" ChartType="Column" Color="Red" ShadowColor="Black" BorderColor="180, 26, 59, 105"  IsValueShownAsLabel="true"   ></asp:series>
								</series>
								<chartareas>
									<asp:chartarea Name="ChartArea1" BorderColor="64, 64, 64, 64" BorderDashStyle="Solid" BackSecondaryColor="White" BackColor="Gainsboro" ShadowColor="Transparent" BackGradientStyle="TopBottom">
										<area3dstyle Rotation="10" perspective="10" Inclination="15" IsRightAngleAxes="False" wallwidth="0" IsClustered="False"></area3dstyle>
										<axisy linecolor="64, 64, 64, 64" IsLabelAutoFit="False">
											<labelstyle font="Trebuchet MS, 8.25pt, style=Bold" />
											<majorgrid linecolor="64, 64, 64, 64" />
										</axisy>
										<axisx linecolor="64, 64, 64, 64" IsLabelAutoFit="False">
											<labelstyle font="Trebuchet MS, 8.25pt, style=Bold" />
											<majorgrid linecolor="64, 64, 64, 64" />
										</axisx>
									</asp:chartarea>
								</chartareas>
							</asp:chart>
				
			</div>
		
			--%>
			
			
<% 
    int width = 75;
    string chartdata = "t:10.8,69.97,34.48,45.78,58.19,42.24,6.86|3,20,9,14,13,11,0";
    string years = string.Empty;
    
    
         IEnumerable<Frogism.Core.YearStat> status = (IEnumerable<Frogism.Core.YearStat>)this.ViewData["YearStats"];

string bookdata = string.Empty;

string pagedata = string.Empty;
        foreach (var v in status)
        {
            if(pagedata!=string.Empty)
            {
                bookdata += ",";
                pagedata += ",";
                
            }
            years += "|";
            width += 50;
            pagedata +=  Math.Round(v.PagesRead / 100d, 2).ToString();
            years +=v.Year.ToString();
            bookdata += v.BooksFinished.ToString();
        }



        string imgurl = @"http://chart.apis.google.com/chart?cht=bvg&chs={0}x250&chd={1}&chbh=a,5,15&chxt=x,y&chxl=0:{2}&chxs=0,ff0000,12,0,lt|1,0000ff,10,1,lt&chco=4D89D9,C6D9FD&chm=N,000000,0,-1,11|N,000000,1,-1,12&chtt=Pages+Read+By+Year&chts=ff0000,16&chdl=Hundreds+of+pages+read|Books+Finished&chdlp=bv";
    chartdata = string.Format("t:{0}|{1}",pagedata,bookdata);
    imgurl = String.Format(imgurl,450,chartdata,years);
    
    %><div style="float:left">
<img src="<%=imgurl %>" style="border:solid 1px black;padding:5px;margin:5px;" width="450" height="250" />
</div>

<%
    IEnumerable<Frogism.Core.YearStat> stats = (IEnumerable<Frogism.Core.YearStat>)this.ViewData["MonthStats"];
    string starturl = @"http://chart.apis.google.com/chart?cht=bvg&chs={0}x250&chd={1}&chbh=a,2,8&chxt=x,y&chxl=0:{2}&chxs=0,ff0000,12,0,lt|1,0000ff,10,1,lt&chco=4D89D9,C6D9FD&chm=N,000000,0,-1,9|N,0000FF,1,-1,9&chtt={3}&chts=ff0000,16&chdl=Pages+read|Previous+year&chdlp=bv&chxr=1,0,800,200&chds=1,800,1,800";
    string thisYear = string.Empty;
    string lastYear = string.Empty;
    string xLabels = string.Empty;
    foreach (var v in stats)
    {
        if (thisYear != string.Empty)
        {
            thisYear += ",";
            lastYear += ",";
        }
        xLabels += "|" + v.Year.ToString();
        thisYear += v.PagesRead.ToString();
        lastYear += v.HistoricRead.ToString();
    }
    string chart2data = string.Format("t:{0}|{1}", thisYear, lastYear);
    string charturl = String.Format(starturl,500,chart2data,xLabels,"Pages+Read+By+Month+for+" + this.ViewData["MonthStatsYear"]);

 %>
 <div style="float:left">
<img src="<%=charturl %>" alt="Chart of Pages Per Month" style="border:solid 1px black; padding:5px;margin:5px;" width="500" height="250" />
</div>
	<br style="clear:both" />
</asp:Content>
